package com.andy.buyu.server.dto;

import java.util.Collection;

import com.andy.buyu.server.game.GameConf;
import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.game.Global;
import com.andy.buyu.server.game.KeepSeet;
import com.andy.buyu.server.game.Room;

import io.netty.buffer.ByteBuf;

/**
 * 大厅机台信息
 * @author cuiwm
 */
public class RoomMessage extends BaseMessage{
	
    
    public RoomMessage() {
	}

	@Override
	public void writeBody(ByteBuf buf) {
		Collection<Room> rooms = Global.getRooms();
		
		buf.writeInt(GameConf.deskSize);
		buf.writeInt(rooms.size());
		for(Room room:rooms) {
			buf.writeInt(room.getId());
			buf.writeByte(room.getType());
			buf.writeInt(room.getMsize()+room.keepSize());
			GameUser[] users = room.getUsers();
			for(int i=0;i<users.length;i++){
				KeepSeet seet = room.keepSeat(i);
				if(users[i] != null || seet != null) {
					buf.writeByte(i);
					if(users[i] != null){
						writeString(buf, users[i].getId().toString());
						buf.writeByte(users[i].getSex());
						buf.writeInt(0);
					}else{
						writeString(buf, seet.getUid().toString());
						buf.writeByte(3);
						buf.writeInt(seet.getLeftTime());
					}
				}
			}
		}
	}


}